package com.ss.sdg.methodcalling;

import java.util.ArrayList;
import java.util.List;

/**
 * MethodCallGraph 
 * @author lijuan wang 
 */
public class MethodCallGraph {

	// MCG name
	private String name;

	// MethodCallNode
	private List<MethodCallNode> nodes;

	// Edge
	private List<Edge> edges;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<MethodCallNode> getNodes() {
		return nodes;
	}

	public void setNodes(List<MethodCallNode> nodes) {
		this.nodes = nodes;
	}

	public List<Edge> getEges() {
		return edges;
	}

	public void setEges(List<Edge> edges) {
		this.edges = edges;
	}

	public MethodCallGraph() {
		super();
		this.nodes = new ArrayList<MethodCallNode>();
		this.edges = new ArrayList<Edge>();
	}

	public void addNode(MethodCallNode node) {
		this.nodes.add(node);
	}

	public void addEge(Edge ege) {
		this.edges.add(ege);
	}

	public void accept(MethodCallVisitor visitor, Object data) {
		visitor.visit(this, data);
	}
	
	public MethodCallNode getMethodCallNode(int nodeId){
		MethodCallNode node=null;
		for(MethodCallNode mcn:nodes){
			if(mcn.getId()==nodeId){
				node=mcn;
				break;
			}
		}
		return node;
	}
	//getMethodCallees
	public List<MethodCallNode> getMethodCallees(MethodCallNode callerNode){
		List<MethodCallNode> list=new ArrayList<MethodCallNode>();
		for(Edge edge:this.edges){
			if(edge.getCaller().getId()==callerNode.getId()){
				list.add(edge.getCallee());
			}
		}
		return list;
	}
}
